package keeto.com.vn.bms.network.task;

import java.io.IOException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.AddTechnicalRequest;
import keeto.com.vn.bms.network.response.AddTechnicalResponse;
import keeto.com.vn.bms.utils.BMSListener;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import android.util.Log;

public class TaskAddTechnical extends AbstractTask {
	private String Schedule_id;
	private String User_id;
	private String AuthKey;

	public TaskAddTechnical(BMSListener listener, IBMSCore core,
			String schedule_id, String user_id, String authKey) {
		super(listener, core);
		Schedule_id = schedule_id;
		User_id = user_id;
		AuthKey = authKey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,IOException {
		AddTechnicalRequest request = new AddTechnicalRequest();
		request.setUser_id(User_id);
		request.setSchedule_id(Schedule_id);
		request.setAuthKey(AuthKey);
		AddTechnicalResponse reponse = protocol.addTechnical(request);
		Log.e("AddTechnicalResponse", reponse.getReturnCode()+"");
		for (BMSListener mListener : listener){
			mListener.finishAddTechnical(reponse.getReturnCode(), reponse.getResultMsg(),reponse.getScheduleTechnicianID());
		}
	}

	@Override
	public void timeoutCallback() {
		for (BMSListener mListener : listener){
			mListener.finishAddTechnical(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, "", "");
		}
	}
	
}
